package 算法;

public class 翻转二叉树 {
    public static void main(String[] args) {

    }
    public TreeNode1 invertTree(TreeNode1 root) {
        if(root != null && (root.left == null && root.right == null)){
            return root;
        }
        TreeNode1 temp = root.left;
        root.left = root.right;
        root.right = temp;

        if(root.left != null) invertTree(root.left);
        if(root.right != null) invertTree(root.right);



        return root;
    }
}
class TreeNode1 {
      int val;
      TreeNode1 left;
      TreeNode1 right;
      TreeNode1(int x) { val = x; }
  }
